<template>
  <div class="card" style="position:relative">
    <van-notice-bar color="#1989fa" background="#ecf9ff" left-icon="info-o" scrollable>
      <span v-html="$route.query.title"></span>
    </van-notice-bar>

    <div style="padding-top:2vh;">
      <van-collapse v-model="activeNames" accordion>

        <!-- 换成通用的遍历jsonbody的模式, 根据editable判断 禁用或启用-->

        <van-collapse-item v-for="item in jsondata.head" :key="item.grouptitle" :name="item.grouptitle"
          :title="item.grouptitle">
          <van-cell-group style="border:0px;">
            <div style="border-bottom:1px solid #ebedf0" v-for="itemdata in item.groupvalue" :key="itemdata.ID">
              <!-- {{itemdata.sUIType}} -->
              <div v-if="itemdata.sUIType == 'datetime'">
                <template v-if="itemdata.sEditable === 'false'">
                  <van-field :id="itemdata.sField" v-model="itemdata.value" disabled :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" v-model="itemdata.value" required disabled clearable
                    :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请输入" :id="itemdata.sField" v-model="itemdata.value" required clearable
                    :label="itemdata.sTitle" @click="openDatePicker(itemdata)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0' && itemdata.idObject == 'weekreports'">
                  <template v-if="itemdata.sField === 'bzjsrq'">
                    <van-field :id="itemdata.sField" v-model="bzjsrqField" disabled clearable :label="itemdata.sTitle"
                      :error-message="itemdata.errormsg" />
                  </template>
                  <template v-if="itemdata.sField === 'xzksrq'">
                    <van-field :id="itemdata.sField" v-model="xzksrqField" disabled clearable :label="itemdata.sTitle"
                      :error-message="itemdata.errormsg" />
                  </template>
                  <template v-if="itemdata.sField === 'xzjsrq'">
                    <van-field :id="itemdata.sField" v-model="xzjsrqField" disabled clearable :label="itemdata.sTitle"
                      :error-message="itemdata.errormsg" />
                  </template>
                  <template v-else>
                    <van-field :id="itemdata.sField" v-model="itemdata.value" disabled clearable
                      :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                  </template>
                </template>

                <template v-else-if="itemdata.lCanInput === '0' && itemdata.idObject != 'weekreports'">
                  <van-field :id="itemdata.sField" v-model="itemdata.value" disabled clearable :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>

                <template v-else>
                  <van-field :id="itemdata.sField" v-model="itemdata.value" placeholder="请输入" readonly clearable
                    :label="itemdata.sTitle" @click="openDatePicker(itemdata)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'code'">
                <template v-if="itemdata.sEditable === 'false'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field :id="itemdata.sField" placeholder="请输入" clearable v-model="itemdata.value"
                    :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'enum' && itemdata.sEditable === 'false'">
                <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                <van-field :id="itemdata.sField + '_enum'" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                  :error-message="itemdata.errormsg" />
              </div>
              <div
                v-else-if="itemdata.sUIType == 'enum' && (itemdata.sUITypeExp == '' || itemdata.sUITypeExp == 'normal')">
                <template v-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" required disabled v-model="itemdata.value"
                    :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请输入" :id="itemdata.sField + '_enum'" required disabled
                    v-model="itemdata.value" :label="itemdata.sTitle" @click="openEnum(itemdata)"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请输入" :id="itemdata.sField + '_enum'" v-model="itemdata.value" readonly
                    :label="itemdata.sTitle" @click="openEnum(itemdata)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'enum' && itemdata.sUITypeExp == 'multi'">
                <template v-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" required disabled v-model="itemdata.value"
                    :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请输入" :id="itemdata.sField + '_enum'" required disabled
                    v-model="itemdata.value" :label="itemdata.sTitle" @click="openEnumMulti(itemdata)"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_enum'" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请输入" :id="itemdata.sField + '_enum'" readonly v-model="itemdata.value"
                    :label="itemdata.sTitle" @click="openEnumMulti(itemdata)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <!-- 先判断ref的sEditable-->
              <div v-else-if="itemdata.sUIType == 'ref' && itemdata.sEditable == 'false'">
                <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                <van-field :id="itemdata.sField + '_ref'" disabled readonly v-model="itemdata.value"
                  :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
              </div>
              <div v-else-if="itemdata.sUIType == 'ref' && itemdata.sUITypeExp == 'normal'">
                <template v-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <input type="hidden" data-flag="1" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_ref'" required disabled v-model="itemdata.value"
                    :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <input type="hidden" data-flag="2" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请选择" :id="itemdata.sField + '_ref'" required clearable
                    v-model="itemdata.value" :label="itemdata.sTitle" right-icon="search"
                    @input="clearRefValue(itemdata)" @clear="clearRefValue(itemdata)"
                    @change="openRef(itemdata, 'headdata', '', 0)"
                    @click-right-icon="openRef(itemdata, 'headdata', '', 0)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <input type="hidden" data-flag="3" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_ref'" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <input type="hidden" data-flag="4" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请选择" :id="itemdata.sField + '_ref'" clearable v-model="itemdata.value"
                    :label="itemdata.sTitle" right-icon="search" @input="clearRefValue(itemdata)"
                    @clear="clearRefValue(itemdata)" @change="openRef(itemdata, 'headdata', '', 0)"
                    @click-right-icon="openRef(itemdata, 'headdata', '', 0)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'ref' && itemdata.sUITypeExp == 'multi'">
                <template v-if="itemdata.sEditable === 'false'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_ref'" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_ref'" required disabled v-model="itemdata.value"
                    :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请选择" :id="itemdata.sField + '_ref'" required clearable
                    v-model="itemdata.value" :label="itemdata.sTitle" right-icon="search"
                    @input="clearRefValue(itemdata)" @clear="clearRefValue(itemdata)"
                    @click-right-icon="openRefMulti(itemdata, 'headdata', '', 0)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_ref'" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请选择" :id="itemdata.sField + '_ref'" clearable v-model="itemdata.value"
                    :label="itemdata.sTitle" right-icon="search" @input="clearRefValue(itemdata)"
                    @clear="clearRefValue(itemdata)" @click-right-icon="openRefMulti(itemdata, 'headdata', '', 0)"
                    :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'bool'">
                <template v-if="itemdata.sEditable === 'false'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_bool'" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_bool'" required disabled v-model="itemdata.value"
                    :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请输入" :id="itemdata.sField + '_bool'" required v-model="itemdata.value"
                    :label="itemdata.sTitle" @click="openBool(itemdata)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field :id="itemdata.sField + '_bool'" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <input type="hidden" :id="itemdata.sField" v-model="itemdata.valuehidden" />
                  <van-field placeholder="请输入" :id="itemdata.sField + '_bool'" :model="itemdata.value == 1 ? '是' : '否'"
                    :label="itemdata.sTitle" @click="openBool(itemdata)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'file'">

                <template v-if="itemdata.sEditable === 'false'">
                  <div class="L-file-lable">{{ itemdata.sTitle }}</div>
                  <div v-for="filevalue in itemdata.valuelist" :key="filevalue.url"
                    style="padding-left:16px;line-height:30px">
                    <span @click="showFiles(filevalue, itemdata.valuelist)">{{ filevalue.file.name }}</span>
                  </div>
                </template>
                <template v-else-if="itemdata.lMustInput === '0'">
                  <div class="L-file-lable">{{ itemdata.sTitle }}</div>
                  <input type="hidden" v-model="itemdata.valuehidden" />
                  <input type="hidden" v-model="itemdata.value" />
                  <van-uploader placeholder="请选择文件" v-model="itemdata.valuelist" :after-read="onFileHead"
                    @delete="delFileHead" accept="*" multiple :name="itemdata.sField">
                  </van-uploader>
                </template>

                <template v-else-if="itemdata.lMustInput === '1'">
                  <div class="L-file-lable"><span style="color:red">*</span> {{ itemdata.sTitle }}
                  </div>
                  <input type="hidden" v-model="itemdata.valuehidden" />
                  <input type="hidden" v-model="itemdata.value" />
                  <van-uploader placeholder="请选择文件" v-model="itemdata.valuelist" :after-read="onFileHead"
                    @delete="delFileHead" accept="*" multiple :name="itemdata.sField">
                  </van-uploader>
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'picture'">
                <template v-if="itemdata.sEditable === 'false'">
                  <div class="L-file-lable">{{ itemdata.sTitle }}</div>
                  <van-uploader v-model="itemdata.valuelist" disabled max-count="0" :deletable="false" />
                </template>
                <template v-else-if="itemdata.lMustInput === '0'">

                  <div class="L-file-lable">{{ itemdata.sTitle }}</div>
                  <input type="hidden" v-model="itemdata.valuehidden" />
                  <input type="hidden" v-model="itemdata.value" />
                  <van-uploader v-model="itemdata.valuelist" placeholder="请上传图片" :after-read="onImageHead"
                    @delete="delImageHead" accept="image/*" multiple :name="itemdata.sField">
                  </van-uploader>
                </template>
                <template v-if="itemdata.lMustInput === '1'">
                  <div class="L-file-lable"><span style="color:red">*</span>{{ itemdata.sTitle }}
                  </div>
                  <input type="hidden" v-model="itemdata.valuehidden" />
                  <input type="hidden" v-model="itemdata.value" />
                  <van-uploader v-model="itemdata.valuelist" placeholder="请上传图片" :after-read="onImageHead"
                    @delete="delImageHead" accept="image/*" multiple :name="itemdata.sField">
                  </van-uploader>
                </template>

              </div>

              <div v-else-if="itemdata.sUIType == 'string' && itemdata.sEditable == 'false'">

                <van-field type="textarea" rows="1" autosize :id="itemdata.sField" disabled v-model="itemdata.value"
                  :label="itemdata.sTitle" :error-message="itemdata.errormsg" />

              </div>

              <div
                v-else-if="itemdata.sUIType == 'string' && (itemdata.sUITypeExp == 'long' || itemdata.sUITypeExp == 'big')">
                <template v-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field type="textarea" rows="1" autosize :id="itemdata.sField" required disabled
                    v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请输入" type="textarea" rows="1" autosize :id="itemdata.sField" required
                    v-model="itemdata.value" :label="itemdata.sTitle" @input="checkData(itemdata)"
                    @blur="checkData(itemdata)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field type="textarea" rows="1" autosize :id="itemdata.sField" disabled v-model="itemdata.value"
                    :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field placeholder="请输入" type="textarea" rows="1" autosize :id="itemdata.sField"
                    v-model="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'string' && itemdata.sFormat == 'star'">
                <template v-if="itemdata.sEditable === 'false'">
                  <van-cell :title="itemdata.sTitle">
                    <template #default>
                      <van-rate v-model="itemdata.value" :size="25" color="#ffd21e" void-icon="star" void-color="#eee"
                        disabled readonly />
                    </template>
                  </van-cell>
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'" required>
                  <van-cell :title="itemdata.sTitle">
                    <template #default>
                      <van-rate v-model="itemdata.value" :size="25" color="#ffd21e" void-icon="star" void-color="#eee"
                        readonly />
                    </template>
                  </van-cell>
                </template>
                <template v-else-if="itemdata.lMustInput === '1'" required placeholder="请输入">
                  <van-cell :title="itemdata.sTitle">
                    <template #default>
                      <van-rate v-model="itemdata.value" :size="25" color="#ffd21e" void-icon="star"
                        void-color="#eee" />
                    </template>
                  </van-cell>
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-cell :title="itemdata.sTitle">
                    <template #default>
                      <van-rate v-model="itemdata.value" :size="25" color="#ffd21e" void-icon="star" void-color="#eee"
                        readonly />
                    </template>
                  </van-cell>
                </template>
                <template v-else placeholder="请输入">
                  <van-cell :title="itemdata.sTitle">
                    <template #default>
                      <van-rate v-model="itemdata.value" :size="25" color="#ffd21e" void-icon="star"
                        void-color="#eee" />
                    </template>
                  </van-cell>
                </template>
              </div>
              <div
                v-else-if="itemdata.sUIType == 'string' && itemdata.sUITypeExp == 'normal' && itemdata.sFormat == 'yearmonth;'">
                <template v-if="itemdata.sEditable === 'false'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>

                <template v-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" required disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请输入" :id="itemdata.sField" required v-model="itemdata.value"
                    :label="itemdata.sTitle" @click="openYearMonth(itemdata)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field placeholder="请输入" :id="itemdata.sField" v-model="itemdata.value" :label="itemdata.sTitle"
                    @click="openYearMonth(itemdata)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div
                v-else-if="itemdata.sUIType == 'string' && (itemdata.idObject == 'account' || itemdata.idObject == 'account1' || itemdata.idObject == 'account2') && itemdata.sField == 'sname'">
                <template v-if="itemdata.sEditable === 'false'">
                  <van-field :id="itemdata.sField" v-model="itemdata.value" disabled :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field :id="itemdata.sField" required v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" @input="solrMatch(itemdata)" placeholder="请输入" />
                  <div id="solrListDiv" :style="solrListDivStyle">
                    <van-list :immediate-check="false" v-model="solrLoading" :finished="solrFinished"
                      finished-text="加载完">
                      <van-cell v-for="solrItem in solrList" :key="solrItem.id" :title="solrItem.sname"
                        @click="choseSolr(solrItem)" />
                    </van-list>
                  </div>
                </template>
              </div>
              <div
                v-else-if="itemdata.sUIType == 'string' && itemdata.sUITypeExp == 'normal' && itemdata.sFormat.indexOf('refer:') >= 0">
                <template v-if="itemdata.sEditable === 'false'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" required disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请输入" :id="itemdata.sField" required readonly v-model="itemdata.value"
                    :label="itemdata.sTitle" @click="openRefer(itemdata)" :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field placeholder="请输入" :id="itemdata.sField" v-model="itemdata.value" readonly
                    :label="itemdata.sTitle" @click="openRefer(itemdata)" :error-message="itemdata.errormsg" />
                </template>
              </div>
              <div v-else-if="itemdata.sUIType == 'map'">
                <template v-if="itemdata.sEditable === 'false'">
                  <van-field :id="itemdata.sField" disabled :value="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" required disabled :value="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请选择" :id="itemdata.sField" required clearable :value="itemdata.value"
                    :label="itemdata.sTitle" right-icon="location-o" @click-right-icon="openMap(itemdata, item)" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" disabled :value="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field placeholder="请选择" :id="itemdata.sField" clearable :value="itemdata.value"
                    :label="itemdata.sTitle" right-icon="location-o" @click-right-icon="openMap(itemdata, item)" />
                </template>
              </div>
              <div v-else>
                <template v-if="itemdata.sEditable === 'false'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>

                <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" required disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lMustInput === '1'">
                  <van-field placeholder="请输入" :id="itemdata.sField" required clearable v-model="itemdata.value"
                    :label="itemdata.sTitle" @input="checkData(itemdata)" @blur="checkData(itemdata)"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else-if="itemdata.lCanInput === '0'">
                  <van-field :id="itemdata.sField" disabled v-model="itemdata.value" :label="itemdata.sTitle"
                    :error-message="itemdata.errormsg" />
                </template>
                <template v-else>
                  <van-field placeholder="请输入" :id="itemdata.sField" clearable v-model="itemdata.value"
                    :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
                  <!--                  <span>测试 {{itemdata.sEditable}} &#45;&#45; {{itemdata.sUIType}} &#45;&#45; {{itemdata.sUITypeExp}}</span>-->
                </template>
              </div>
            </div>

          </van-cell-group>
        </van-collapse-item>

      </van-collapse>
    </div>
    <div style="padding-top:2vh;padding-bottom:2vh;">
      <van-tabs @click="openRel">
        <van-tab v-for="rel in jsondata.relevant" :key="rel.ui_key" :title="rel.title" :name="rel.ui_key">
          <van-list v-model="loading" :finished="finished" finished-text="已加载全部数据" @load="onLoad(rel)">
            <div v-for="item in rellist" :key="item.id">
              <template v-if="rel.current_object == 'flowclmx' || rel.current_object == 'flowrecord'">
                <van-cell>
                  <template #title>
                    <span v-html="item.title"></span><br>
                    <span style="font-size: 12px;color: #969799;" v-html="item.label"></span>
                  </template>
                  <template>
                    <span v-html="item.value"></span>
                  </template>
                </van-cell>
              </template>
              <template v-else>
                <van-cell @click="openRelCard(rel, item)">
                  <template #title>
                    <span v-html="item.title"></span><br>
                    <span style="font-size: 12px;color: #969799;" v-html="item.label"></span>
                  </template>
                  <template>
                    <span v-html="item.value"></span>
                  </template>
                </van-cell>
              </template>
            </div>
          </van-list>
        </van-tab>
      </van-tabs>
    </div>

    <van-popup v-model="datepickershow" round position="bottom" :style="{ height: '40%' }">
      <van-datetime-picker v-model="currentDate" type="date" @confirm="selectedDate" />
    </van-popup>
    <van-popup v-model="datetimeshow" round position="bottom">
      <van-datetime-picker v-model="currentDate" type="datetime" @confirm="selectedDateTime" />
    </van-popup>
    <van-action-sheet v-model="enumshow" :actions="actions" @select="selectedEnum" />
    <van-popup v-model="enumMultishow" round position="bottom">
      <van-checkbox-group v-model="selecteddata" ref="checkboxGroup">
        <van-cell v-for="(item, index) in enumMulti" :key="item.id" :title="item.name" @click="toggle(index)">
          <van-checkbox :name="item" ref="checkboxes" slot="right-icon" />
        </van-cell>
      </van-checkbox-group>
      <div style="text-align:right;padding-right:10vw;padding-top:2vh;padding-bottom:2vh;">
        <van-button type="info" size="small" @click="selectedEnumMulti">确认</van-button>
      </div>
    </van-popup>

    <div style="margin-bottom:10vh;">
      <!-- <van-steps direction="vertical" :active="0">
        <van-step v-for="(item, index) in jsondata.history" :key="index">
          <h3 style="margin:0;font-weight:normal;font-size:inherit;">{{ item.user }} | {{ item.status }}</h3>
          <p>{{ item.operationtime }} | {{ item.opinion }}</p>
        </van-step>
      </van-steps> -->
      <time-line :alldata="jsondata.history"></time-line>
      <!-- <timeLine :alldata="jsondata.history"></timeLine> -->
    </div>

    <van-popup v-model="relcardshow" position="right" closeable style="width:90vw;">
      <div style="padding-top:5vh;">
        <van-collapse v-model="relactiveNames">
          <van-collapse-item v-for="item in reldata.Details" :key="item.groupStitle" :name="item.groupStitle"
            :title="item.groupStitle">
            <van-cell v-for="fieldvalue in item.groupvalue" :key="fieldvalue.id" :title="fieldvalue.sTitle"
              :value="fieldvalue.value">
              <template #default>
                <!-- <div v-if="fieldvalue.sUIType==='picture'">
                 <div v-for="(fileitem,index) in fieldvalue.valuelist" :key="index">
                    <span @click="showFile(fileitem)" style="font-size:12px">{{fileitem.file.name}}</span>
                  </div>
                </div> -->

                <div v-if="fieldvalue.sUIType === 'file' || fieldvalue.sUIType === 'picture'">

                  <!-- <van-image-preview v-model="show" :images="fieldvalue.valuelist.map(file=>file.url)" @change="onChange">
                    <template v-slot:index>第{{ index }}页</template>
          </van-image-preview> -->

                  <div v-for="(fileitem, index) in fieldvalue.valuelist" :key="index">
                    <span @click="showFile(fileitem)" style="font-size:12px"> {{ fileitem.file.name }};</span>
                  </div>
                </div>
                <div v-else v-html="fieldvalue.value"></div>
              </template>
            </van-cell>
          </van-collapse-item>
        </van-collapse>
      </div>
    </van-popup>


    <van-popup v-model="relcardshow1" position="right" closeable style="width:90vw;height: 100%;">
     
        <FlowcardBodyForm v-if="relcardshow1" @afterBodyFormSave="afterBodyFormSave" :idobject="bodyObject"
          :itemid="currentTabItemid">
        </FlowcardBodyForm>
 
    </van-popup>

    <!-- <van-popup v-model="optionshow" position="top" style="width:100vw;height:300px">
      <van-panel title="审批意见1">
        <div>
          <van-field v-model="opinion" rows="1" autosize label="意见" type="textarea" placeholder="请输入" />
        </div>
        <div slot="footer" style="text-align:right;">
          <van-button size="small" @click="execFlow">确认</van-button>
        </div>
      </van-panel>
    </van-popup> -->
    <!-- <div class="L-popup-container" v-show="optionshow">
      <div class="L-optionBox">
         <div style="text-align:right"><i class="el-icon-close" @click="optionshow=false"></i></div>
        <div class="L-optionBox-title">
          审批意见
        </div>
        <div class="messageBox">
          <van-field maxlength="100" style="border-radius:6px" show-word-limit v-model="opinion" rows="2" autosize type="textarea" placeholder="请输入留言" />
        </div>
        <div>
          <van-uploader >
            <van-button plain  block class="L-upload-btn" icon="back-top" type="default">上传附件</van-button>
          </van-uploader>
        </div>
        <div class="L-fileBox">
          <div class="L-fileBox-item" v-for="item in optionFileList" :key="item.id">
            <i class="el-icon-link"></i>
            {{item.fileName}}
          </div>
        </div>
        <div>
          <van-button round   block class="L-upload-btn"  type="info">提交</van-button>
        </div>

      </div>
    </div> -->

    <van-popup duration="0.1" v-model="optionshow" position="bottom" :style="{ 'height': optionPopupHeight }"
      class="L-popup-container" :lock-scroll="false" :overlay="false">

      <div class="L-optionBox">

        <div class="L-optionBox-title">
          <div>审批意见</div>
          <div style="text-align:right"><i class="el-icon-close" @click="optionshow = false"></i></div>
        </div>
        <div class="messageBox">
          <van-field maxlength="100" style="border-radius:6px" show-word-limit v-model="opinion" rows="2" autosize
            type="textarea" placeholder="请输入留言" />
        </div>
        <div v-if="cardoperation === 'agree'">
          <van-uploader :preview-image="false" placeholder="请选择文件" v-model="filelist" :after-read="handleUpload"
            accept="*" multiple>
            <van-button plain block class="L-upload-btn" icon="back-top" type="default">上传附件</van-button>
          </van-uploader>
        </div>
        <div class="L-fileBox" v-if="cardoperation === 'agree'">
          <div class="L-fileBox-item" v-for="item in fileList" :key="item.newname">
            <i class="el-icon-link"></i>
            {{ item.oldname }}
          </div>
        </div>
        <div style="margin-top:20px">
          <van-button round block class="L-upload-btn" type="info" @click="execFlow">提交</van-button>
        </div>

      </div>
    </van-popup>

    <van-popup v-model="turndoneshow" style="width:80vw;">
      <van-panel title="审批意见">
        <div>
          <input type="hidden" v-model="clr_id" />
          <van-field v-model="clr" label="处理人" type="text" @click="openDealRef" />
          <van-field v-model="opinion" rows="1" autosize label="意见" type="textarea" placeholder="请输入" />
        </div>
        <div slot="footer" style="text-align:right;">
          <van-button size="small" @click="execFlow">确认</van-button>
        </div>
      </van-panel>
    </van-popup>
    <!-- <van-popup v-model="optionshow">

    </van-popup> -->
    <div :style="{ 'height': optionPopupHeight }" v-show="optionshow">&nbsp;</div>
    <van-tabbar v-model="active" safe-area-inset-bottom>
      <van-tabbar-item v-show="actiontype === 'mytask' && actioncode === 'unhandle' && isowner === '1'"
        @click="openOpinion('agree')">
        <!-- 同意 -->
        <el-button type="success" size="medium" round plain>同意</el-button>
      </van-tabbar-item>
      <van-tabbar-item v-show="actiontype === 'mytask' && actioncode === 'unhandle' && isowner === '1'"
        @click="openOpinion('turndone')">
        <!-- 转办 -->
        <el-button type="primary" size="medium" round plain>转办</el-button>
      </van-tabbar-item>
      <van-tabbar-item v-show="actiontype === 'mytask' && actioncode === 'unhandle' && isowner === '1'"
        @click="openOpinion('sendback')">
        <!-- 退回 -->
        <el-button type="warning" size="medium" round plain>退回</el-button>
      </van-tabbar-item>

      <van-tabbar-item v-show="actiontype === 'mytask' && actioncode === 'unhandle' && isowner === '1'"
        @click="openOpinion('veto')">
        <!-- 否决 -->
        <el-button type="danger" size="medium" round plain>否决</el-button>
      </van-tabbar-item>

      <van-tabbar-item v-show="actiontype === 'mytask' && actioncode === 'unhandle' && isowner === '1'"
        @click="showFlowNodePopup = true">
        <!-- 查看流程 -->
        <el-button type="success" size="medium" round plain>流程</el-button>
      </van-tabbar-item>
      <van-tabbar-item v-show="actiontype === 'mysend' && actioncode === 'unhandle'" @click="submit">
        提交
        <!-- <el-button type="primary" size="medium" round plain>提交</el-button> -->
      </van-tabbar-item>
      <van-tabbar-item v-show="(actiontype === 'mytask' || actiontype === 'mysend') && actioncode === 'handle'"
        @click="back">
        取回
      </van-tabbar-item>
      <van-tabbar-item v-show="actiontype === 'mytask' && actioncode === 'handle' && procestype === '已完成'"
        @click="unaudit">
        弃审
      </van-tabbar-item>
      <van-tabbar-item v-show="actiontype !== 'mytask'" @click="showFlowNodePopup = true">
        流程查看
      </van-tabbar-item>
    </van-tabbar>

    <van-popup v-model="showFlowNodePopup" closeable round position="bottom" :style="{ height: '70%' }">
      <div style="text-align:center;margin:10px auto">审批流程</div>

      <van-steps direction="vertical" :active="hasWillFlowNode ? flowNodeArr.length - 2 : flowNodeArr.length - 1"
        active-color="#38f">
        <van-step v-for="(item, index) in flowNodeArr" :key="index">
          <b>{{ item.nodeName }}</b>
          <p v-if="item.time != 1">{{ item.time }}</p>
          <p>{{ item.name }} | {{ item.status }}</p>
        </van-step>

      </van-steps>

    </van-popup>




  </div>

</template>

<script>
import Vue from 'vue'
import { Icon, Search, List, Cell, PullRefresh, Toast, Tabbar, TabbarItem, Popup, DatetimePicker, ActionSheet, Tab, Tabs, Collapse, CollapseItem, Dialog, Step, Steps, Checkbox, CheckboxGroup, Uploader, ImagePreview } from 'vant'
import qs from 'qs'
import { opinionPopup } from '@/components/opinionPopup'
import timeLine from '@/components/timeLine'
import FlowcardBodyForm from "@/views/flow/FlowcardBodyForm"

Toast.setDefaultOptions({ type: 'html' })

Vue.use(Icon).use(Search).use(List).use(Cell).use(PullRefresh).use(Toast).use(Tabbar).use(TabbarItem).use(Popup).use(DatetimePicker).use(ActionSheet).use(Checkbox).use(CheckboxGroup).use(Tab).use(Tabs).use(Collapse).use(CollapseItem).use(Dialog).use(Step).use(Steps).use(Uploader)
export default {
  name: 'flowcard',
  components: {
    'time-line': timeLine,
    [ImagePreview.Component.name]: ImagePreview.Component,
    'FlowcardBodyForm': FlowcardBodyForm
  },
  data() {
    return {
      currentTabObjectRel:"",
      bodyObject:"",
      currentTabItemid:"",
      fileInfo: {},
      fileList: [],
      flowNodeArr: [],
      showFlowNodePopup: false,
      hasWillFlowNode: false,
      optionFileList: [
        { id: 0, fileName: '招标文件.doc' },
        { id: 1, fileName: '本季度订单列表.doc' },
        { id: 0, fileName: '招标文件.doc' },
        { id: 1, fileName: '本季度订单列表.doc' }
      ],
      optionPopupHeight: '450px',
      idobject: this.$route.query.idobject,
      actiontype: this.$route.query.actiontype,
      actioncode: this.$route.query.actioncode,
      idbill: this.$route.query.idbill,
      idflow: this.$route.query.idflow,
      procestype: this.$route.query.procestype,
      jsondata: {},
      index: 0,
      active: 0,
      activeNames: '',
      optionshow: false,
      turndoneshow: false,
      cardoperation: '',
      opinion: '',
      clr_id: '',
      clr: '',
      loading: false,
      finished: false,
      rellist: [],
      startline: 1,
      pagecount: 20,
      relcardshow: false,
      relcardshow1: false,
      reldata: {},
      relactiveNames: [],
      isDisable: false,
      enumshow: false,
      enumMultishow: false,
      enumMulti: [],
      selecteddata: [],
      actions: [],
      clickmodel: {},
      datepickershow: false,
      currentDate: '',
      datetimeshow: false,
      isowner: '0'
    }
  },
  created: function () {
    let data = { idbill: this.idbill, idflow: this.$route.query.idflow, idobject: this.$route.query.idobject }
    const url = this.actiontype === 'mytask' && this.actioncode === 'handle' ? '/api/flowrecord.check.do' : '/api/flowclmx.check.do';
    this.axios({
      method: 'post',
      url: url,
      data: qs.stringify(data)
    }).then(res => {
      //console.log(res)
      if (res.data.flag === '1') {
        Toast(res.data.des)
        if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
          this.loginout()
        }
      } else {
        this.jsondata = res.data.jsondata
        this.isowner = this.jsondata.isowner
        this.bodyObject = res.data.jsondata.relevant.find(item=>item.isbody)?.current_object || ""
        this.currentTabObjectRel = this.jsondata.relevant[0]

        // Toast(this.isowner)
      }
    }).catch(res => {
      this.reserror(res)
    })

    this.getFlowNodes()
  },
  methods: {

    afterBodyFormSave() {
      this.relcardshow1 = false
      this.reLoad(this.currentTabObjectRel)
    },
    reLoad(rel) {
      let data = {
        'startline': this.startline,
        'pagecount': this.pagecount,
        'relfield': rel.relfield,
        'relvalue': this.idbill
      }
      let url = ''
      if (rel.current_object === 'flowclmx') {
        url = '/api/' + rel.current_object + '.list-rel.do'
      } else {
        url = '/api/' + rel.current_object + '.list.do'
      }
     
      this.activeNames = '基本信息'
      this.axios({
        method: 'post',
        url: url,
        data: qs.stringify(data)
      }).then(res => {
        //console.log(res)
        if (res.data.flag === '1') {
          Toast(res.data.des)
          if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
            this.loginout()
          }
        } else {
          let rsdata = res.data.jsondata.fieldValue
          this.rellist = rsdata
          // for (let i = 0; i < rsdata.length; i++) {
          //   this.rellist.push(rsdata[i])
          // }
          if (rsdata == null || rsdata.length === 0 || rsdata.length < this.pagecount) {
            this.loading = false
            this.finished = true
          } else {
            this.startline = this.startline + rsdata.length
            this.loading = false
          }
        }
      }).catch(res => {
        this.reserror(res)
      })
    },
    getFlowNodes() {

      const data = {
        idBill: this.idbill,
        bo: this.$route.query.idobject
      }

      this.axios({
        method: 'post',
        url: '/api/flowwork.btncheckflowwork.do',
        data: qs.stringify(data)
      }).then(res => {

        if (res.data.flag === '1') {
          Toast(res.data.des)
          if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
            this.loginout()
          }
        } else {


          const nodes = res.data.jsondata.clmxDateMap
          const arr1 = []
          const arr2 = []
          Object.keys(nodes).forEach(item => {
            const node = JSON.parse(nodes[item])
            if (Number(node.procestate) !== 5) {
              arr1.push({ time: item, name: node.username, status: this.getFlowNodesStatus(Number(node.procestate)), nodeName: node.nodeName })
            } else {
              arr2.push({ time: item, name: node.username, status: this.getFlowNodesStatus(Number(node.procestate)), nodeName: node.nodeName })
            }
          })
          if (arr2.length > 0) {
            this.hasWillFlowNode = true
          }

          this.flowNodeArr = [...arr1, ...arr2]

          // this.isowner = this.jsondata.isowner
          // Toast(this.isowner)
        }
      })
    },

    getFlowNodesStatus(statusNum) {
      let action = ""
      switch (statusNum) {
        case 1: action = "待发"; break;
        case 2: action = "已发"; break;
        case 3: action = "待办"; break;
        case 4: action = "已办"; break;
        case 5: action = "将要进行"; break;
        case 6: action = "已否决"; break;
        default: action = "无操作";
      }
      return action


    },
    showFiles(file, fileArr) {
      const imageTypeArr = ['jpg', 'png', 'gif']
      const fileExtension = file.url.split('.').pop()
      //console.log('****', fileExtension)
      if (imageTypeArr.indexOf(fileExtension) === -1) {
        window.location.href = file.url
      } else {
        const imgArr = fileArr.filter((item) => {
          const itemFileExtension = item.url.split('.').pop()
          return imageTypeArr.indexOf(itemFileExtension) !== -1
        }).map(item => {
          return item.url
        })
        ImagePreview({
          images: imgArr,
          showIndex: true
        })
      }
    },

    showFile(fileitem) {
      //console.log('***', fileitem)
      const imageTypeArr = ['jpg', 'png', 'gif']

      const fileExtension = fileitem.url.split('.').pop()
      if (imageTypeArr.indexOf(fileExtension) === -1) {
        window.location.href = fileitem.url
      } else {
        ImagePreview({
          images: [fileitem.url],
          showIndex: false
        })
      }
    },

    handleUpload(file, detail) {
      // 上传
      let deviceFile = []
      let formData = new FormData()
      if (Array.isArray(file)) {
        deviceFile = file
      } else {
        deviceFile.push(file)
      }
      for (let i = 0; i < deviceFile.length; i++) {
        formData.append('file' + i, deviceFile[i].file, deviceFile[i].name)
      }
      this.axios({
        method: 'post',
        url: '/api/upload.filedo',
        data: formData,
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }).then(res => {
        if (res.data.flag === '0') {
          let fileInfo = res.data.fileInfo
          const newnameList = fileInfo[0].newname.split(';')
          const oldnameList = fileInfo[0].oldname.split(';')
          const fileList = newnameList.map((item, index) => {
            const file = { newname: item, oldname: oldnameList[index] }
            return file
          })

          this.fileList = [...this.fileList, ...fileList]

          for (let headIdx = 0; headIdx < this.jsondata.head.length; headIdx++) {
            let headData = this.jsondata.head[headIdx].groupvalue
            for (let i = 0; i < headData.length; i++) {
              if (headData[i].sField === detail.name) {
                headData[i].valuehidden = fileInfo[0].newname
                headData[i].value = fileInfo[0].oldname
              }
            }
          }
          Toast('上传成功')
        } else {
          Toast('上传失败')
        }
      }).catch(res => {
        //console.log(res)
      })
      // let headdata = this.jsondata.head[0].groupvalue
      //console.log(file)
      //console.log(detail)
    },
    selectedDate() {
      //console.log(this.currentDate)
      let year = this.currentDate.getFullYear() // 获取完整的年份(4位,1970-????)
      let month = this.currentDate.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
      let day = this.currentDate.getDate() // 获取当前日(1-31)
      if (month < 10) {
        month = '0' + month
      }
      if (day < 10) {
        day = '0' + day
      }
      let dateString = year + '-' + month + '-' + day
      this.clickmodel.value = dateString
      this.datepickershow = false
    },
    selectedDateTime() {
      //console.log(this.currentDate)
      let year = this.currentDate.getFullYear() // 获取完整的年份(4位,1970-????)
      let month = this.currentDate.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
      let day = this.currentDate.getDate() // 获取当前日(1-31)
      let hour = this.currentDate.getHours()
      let minute = this.currentDate.getMinutes()
      if (month < 10) {
        month = '0' + month
      }
      if (day < 10) {
        day = '0' + day
      }
      if (hour < 10) {
        hour = '0' + hour
      }
      if (minute < 10) {
        minute = '0' + minute
      }
      let dateString = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':00' // ios强制要求日期格式为2022/01/01
      this.clickmodel.value = dateString
      this.clickmodel.errormsg = ''
      this.datetimeshow = false
    },
    openYearMonth(datamodel) {
      if (datamodel.value != null && datamodel.value !== undefined && datamodel.value !== '') {
        datamodel.value = datamodel.value.substring(0, 7)
        this.currentYearMonth = new Date(datamodel.value)
      }
      this.clickmodel = datamodel
      this.yearmonthshow = true
    },
    selectedYearMonth() {
      //console.log(this.currentYearMonth)
      let year = this.currentYearMonth.getFullYear()
      let month = this.currentYearMonth.getMonth() + 1
      if (month < 10) {
        month = '0' + month
      }
      let datestring = year + '-' + month
      this.clickmodel.value = datestring
      this.clickmodel.errormsg = ''
      this.yearmonthshow = false
    },

    openDatePicker(datamodel) {
      if (datamodel.value != null && datamodel.value !== undefined && datamodel.value !== '') {
        if (datamodel.sUITypeExp !== 'long') {
          datamodel.value = datamodel.value.substring(0, 10)
        }
        let newDate = new Date(datamodel.value.replace(/-/g, '/'))
        this.currentDate = new Date(newDate)
      }
      this.clickmodel = datamodel
      if (datamodel.sUITypeExp === 'long') {
        this.datetimeshow = true
      } else {
        this.datepickershow = true
      }
    },
    openEnum(datamodel) {
      //console.log(JSON.stringify(datamodel))
      this.actions = []
      this.clickmodel = datamodel
      let enumid = datamodel.allenumid
      let arrEnumid = enumid.split(';')
      let enumval = datamodel.allenumval
      let arrEnumval = enumval.split(';')
      for (let i = 0; i < arrEnumid.length; i++) {
        this.actions.push({ id: arrEnumid[i], name: arrEnumval[i] })
      }
      this.enumshow = true
    },
    selectedEnum(item) {
      this.clickmodel.valuehidden = item.id
      this.clickmodel.value = item.name
      this.enumshow = false
    },
    openEnumMulti(datamodel) {
      this.enumMulti = []
      this.selecteddata = []
      this.clickmodel = datamodel
      let enumid = datamodel.allenumid
      let arrEnumid = enumid.split(';')
      let enumval = datamodel.allenumval
      let arrEnumval = enumval.split(';')
      for (let i = 0; i < arrEnumid.length; i++) {
        if (arrEnumid[i] === '') {
          continue
        }
        this.enumMulti.push({ id: arrEnumid[i], name: arrEnumval[i] })
      }
      this.enumMultishow = true
    },
    toggle(index) {
      this.$refs.checkboxes[index].toggle()
    },
    selectedEnumMulti() {
      let enumid = ''
      let enumval = ''
      this.clickmodel.valuehidden = ''
      this.clickmodel.value = ''
      for (let i = 0; i < this.selecteddata.length; i++) {
        enumid += this.selecteddata[i].id + ';'
        enumval += this.selecteddata[i].name + ';'
      }
      this.clickmodel.valuehidden = enumid
      this.clickmodel.value = enumval
      this.clickmodel.errormsg = ''
      this.enumMultishow = false
    },
    openRefMulti(datamodel, datafrom, indexName, index) {
      this.clickmodel = datamodel
      this.clickfrom = datafrom
      this.clickindex = index
      this.conditionValHidden = ''
      let inview = datamodel.inview
      if (inview !== '') {
        let arrinview = inview.split(';')
        for (let inviewindex in arrinview) {
          let arrinviewdata = arrinview[inviewindex]
          let inviewdatas = arrinviewdata.split(':')
          if (inviewdatas[1] === 'eq') {
            if (datafrom === 'headdata') {
              for (let groupindex in this.jsondata.head) {
                for (let itemindex in this.jsondata.head[groupindex].groupvalue) {
                  let item = this.jsondata.head[groupindex].groupvalue[itemindex]
                  if (item.sField === inviewdatas[2].split('_')[2]) {
                    this.conditionValHidden += inviewdatas[0] + ':eqref:' + item.valuehidden + ';'
                  }
                }
              }
            } else if (datafrom === 'bodydata') {
              for (let itemindex in this.jsondata.bodydata[indexName][index]) {
                let item = this.jsondata.bodydata[indexName][index][itemindex]
                if (item.sField === inviewdatas[0]) {
                  this.conditionValHidden += inviewdatas[0] + ':eqref:' + item.valuehidden + ';'
                }
              }
            }
          } else if (inviewdatas[1] === 'in') {
            this.conditionValHidden += inviewdatas[0] + ':in:;'
          }
        }
      }
      // 每个逻辑需要单独写
      if (datamodel.idObject === 'sorders' && datamodel.jsfunc === 'getAccountForSorder()') {
        let agent = ''
        let consumer = ''
        let type = ''
        for (let groupindex in this.jsondata.head) {
          for (let itemindex in this.jsondata.head[groupindex].groupvalue) {
            let item = this.jsondata.head[groupindex].groupvalue[itemindex]
            if (item.sField === 'agent') {
              agent = item.valuehidden
            } else if (item.sField === 'consumer') {
              consumer = item.valuehidden
            } else if (item.sField === 'type') {
              type = item.valuehidden
            }
          }
        }
        if (consumer === '') {
          Toast('请先选择客户')
          return
        }
        if (type === '297ef43353a100de0153a1fdcaa60611') {
          if (agent !== '') {
            Toast('自营模式不能输入代理商')
            return
          }
        } else {
          if (agent === '') {
            Toast('请先选择代理商')
            return
          }
        }
      }
      let refname = 'refmulti'
      if (datamodel.idJoinObject === 'employee') {
        refname = 'idownerMulti'
      }
      this.$router.push({
        name: refname,
        params: {
          bo: datamodel.idJoinObject,
          tobo: datamodel.idObject,
          field: datamodel.sField,
          fieldref: datamodel.sFieldRef,
          viewid: datamodel.sRefKey,
          conditionVal: '',
          conditionValHidden: this.conditionValHidden,
          classname: datamodel.classname,
          valuehidden1: datamodel.valuehidden,
          datamodel1: datamodel
        }
      })
    },

    openRef(datamodel, datafrom, indexName, index) {
      this.clickmodel = datamodel
      this.clickfrom = datafrom
      this.clickindex = index
      this.conditionValHidden = ''
      let inview = datamodel.inview
      if (inview !== '') {
        let arrinview = inview.split(';')
        for (let inviewindex in arrinview) {
          let arrinviewdata = arrinview[inviewindex]
          let inviewdatas = arrinviewdata.split(':')
          if (inviewdatas[1] === 'eq') {
            if (datafrom === 'headdata') {
              for (let groupindex in this.jsondata.head) {
                for (let itemindex in this.jsondata.head[groupindex].groupvalue) {
                  let item = this.jsondata.head[groupindex].groupvalue[itemindex]
                  if (item.sField === inviewdatas[2].split('_')[2]) {
                    this.conditionValHidden += inviewdatas[0] + ':eqref:' + item.valuehidden + ';'
                  }
                }
              }
            } else if (datafrom === 'bodydata') {
              for (let itemindex in this.jsondata.bodydata[indexName][index]) {
                let item = this.jsondata.bodydata[indexName][index][itemindex]
                if (item.sField === inviewdatas[0]) {
                  this.conditionValHidden += inviewdatas[0] + ':eqref:' + item.valuehidden + ';'
                }
              }
            }
          } else if (inviewdatas[1] === 'in') {
            this.conditionValHidden += inviewdatas[0] + ':in:;'
          }
        }
      }
      this.$router.push({
        name: 'ref',
        params: {
          bo: datamodel.idJoinObject,
          tobo: datamodel.idObject,
          field: datamodel.sField,
          fieldref: datamodel.sFieldRef,
          viewid: datamodel.sRefKey,
          conditionVal: '',
          conditionValHidden: this.conditionValHidden
        }
      })
    },
    clearRefValue(datamodel) {
      if (datamodel.value === '') {
        datamodel.valuehidden = ''
      }
    },
    openOpinion(operation) {
      if (operation === 'agree') {
        this.optionshow = true
      } else if (operation === 'turndone') {
        this.turndoneshow = true
      } else if (operation === 'sendback') {
        this.optionshow = true
      } else if (operation === 'veto') {
        this.optionshow = true
      }
      this.cardoperation = operation
    },
    execFlow() {
      if (this.cardoperation === 'agree') {
        this.agree()
      } else if (this.cardoperation === 'turndone') {
        this.turndone()
      } else if (this.cardoperation === 'sendback') {
        this.sendback()
      } else if (this.cardoperation === 'veto') {
        this.veto()
      }
    },
    openDealRef() {
      this.$router.push({
        // name: 'ref',
        name: 'orgRef',
        params: {
          bo: 'employee',
          tobo: 'flowclmx',
          field: 'clr',
          fieldref: 'sname',
          viewid: '13002637001710527179865071935319',
          conditionVal: '',
          conditionValHidden: 'sname:in:;',
          classname: ''
        }
      })
    },

    agree() {
      if (!this.isDisable) {
        this.isDisable = true
        this.overlayShow = true
        let filename = ''
        let filetitle = ''

        if (this.fileList.length > 0) {
          this.fileList.forEach((item, index) => {
            if (index < this.fileList.length - 1) {
              filename += item.newname + ';'
              filetitle += item.oldname + ';'
            } else {
              filename += item.newname
              filetitle += item.oldname
            }
          })
        }

        let data = { opinion: this.opinion, 'batchoperation': this.idflow + ';', bo: this.idobject, filename, filetitle }
        let cansave = 1
        data[this.idobject + '_id'] = this.idbill
        data[this.idobject + '_idtemplate'] = this.idtemplate
        for (let groupindex in this.jsondata.head) {
          let itemgroup = this.jsondata.head[groupindex].groupvalue
          for (let itemindex in itemgroup) {
            let itemdata = itemgroup[itemindex]
            if (itemdata.sUIType === 'ref') {
              if (itemdata.lMustInput === '1' && itemdata.value === '') {
                itemdata.errormsg = '不能为空'
                cansave = 0
              }
              data[itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
              data[itemdata.idObject + '_' + itemdata.sField + '_ref'] = itemdata.value
            } else if (itemdata.sUIType === 'enum') {
              if (itemdata.lMustInput === '1' && itemdata.value === '') {
                itemdata.errormsg = '不能为空'
                cansave = 0
              }
              data[itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
              data[itemdata.idObject + '_' + itemdata.sField + '_enum'] = itemdata.value
            } else if (itemdata.sUIType === 'file' || itemdata.sUIType === 'picture') {
              if (itemdata.lMustInput === '1' && itemdata.value === '') {
                alert(itemdata.sTitle + '不能为空')
                itemdata.errormsg = '不能为空'
                cansave = 0
              }
              if (!itemdata.valuehidden) {
                data[itemdata.idObject + '_' + itemdata.sField] = itemdata.value
              } else {
                data[itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
              }
              data[itemdata.idObject + '_' + itemdata.sField + '_title'] = itemdata.value
            } else {
              if (itemdata.lMustInput === '1' && itemdata.value === '') {
                itemdata.errormsg = '不能为空'
                cansave = 0
              }
              data[itemdata.idObject + '_' + itemdata.sField] = itemdata.value
            }
          }
        }
        if (this.jsondata.hasdetail === '1') {
          for (let indexName in this.jsondata.bodydata) {
            for (let i = 0; i < this.jsondata.bodydata[indexName].length; i++) {
              let item = this.jsondata.bodydata[indexName][i]
              for (let itemindex in item) {
                let itemdata = item[itemindex]
                if (itemdata.sUIType === 'ref') {
                  if (itemdata.lMustInput === '1' && itemdata.value === '') {
                    itemdata.errormsg = '不能为空'
                    cansave = 0
                  }
                  data[i + '_' + itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
                  data[i + '_' + itemdata.idObject + '_' + itemdata.sField + '_ref'] = itemdata.value
                } else if (itemdata.sUIType === 'enum') {
                  if (itemdata.lMustInput === '1' && itemdata.value === '') {
                    itemdata.errormsg = '不能为空'
                    cansave = 0
                  }
                  data[i + '_' + itemdata.idObject + '_' + itemdata.sField] = itemdata.valuehidden
                  data[i + '_' + itemdata.idObject + '_' + itemdata.sField + '_enum'] = itemdata.value
                } else {
                  if (itemdata.lMustInput === '1' && itemdata.value === '') {
                    itemdata.errormsg = '不能为空'
                    cansave = 0
                  }
                  data[i + '_' + itemdata.idObject + '_' + itemdata.sField] = itemdata.value
                }
              }
            }
          }
        }
        //console.log('jsondata', this.jsondata)
        if (cansave === 0) {
          this.isDisable = false
          this.overlayShow = false
          Toast('请检查必输项!')
          return
        }

        this.axios({
          method: 'post',
          url: '/api/flowclmx.agree.do',
          data: qs.stringify(data)
        }).then(res => {
          //console.log(res)
          Toast(res.data.des)
          if (res.data.flag === '1') {
            if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
              this.loginout()
            }
          }
          this.isDisable = false
          this.$router.push({
            name: 'flowlist',
            query: { idobject: 'flowclmx', actiontype: this.actiontype, actioncode: this.actioncode }
          })
        }).catch(res => {
          this.isDisable = false
          //console.log(res)
          Toast(res)
        })
      }
    },

    turndone() {
      if (!this.isDisable) {
        this.isDisable = true
        let data = {
          idobject: this.idobject,
          idbill: this.idbill,
          opinion: this.opinion,
          'batchoperation': this.$route.query.idflow,
          clrid: this.clr_id,
          clr: this.clr
        }
        this.axios({
          method: 'post',
          url: '/api/flowclmx.turndone.do',
          data: qs.stringify(data)
        }).then(res => {
          //console.log(res)
          Toast(res.data.jsondata)
          this.isDisable = false
          this.$router.push({
            name: 'flowlist',
            query: { idobject: 'flowclmx', actiontype: this.actiontype, actioncode: this.actioncode }
          })
        }).catch(res => {
          this.isDisable = false
          //console.log(res)
          Toast(res)
        })
      }
    },

    sendback() {
      if (!this.isDisable) {
        this.isDisable = true
        let data = { opinion: this.opinion, 'batchoperation': this.$route.query.idflow }
        this.axios({
          method: 'post',
          url: '/api/flowclmx.batsendback.do',
          data: qs.stringify(data)
        }).then(res => {
          //console.log(res)
          Toast(res.data.des)
          if (res.data.flag === '1') {
            if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
              this.loginout()
            }
          }
          this.isDisable = false
          this.$router.push({
            name: 'flowlist',
            query: { idobject: 'flowclmx', actiontype: this.actiontype, actioncode: this.actioncode }
          })
        }).catch(res => {
          this.isDisable = false
          //console.log(res)
          Toast(res)
        })
      }
    },

    veto() {
      if (!this.isDisable) {
        this.isDisable = true
        let data = { idobject: this.idobject, opinion: this.opinion, 'idflow': this.$route.query.idflow }
        this.axios({
          method: 'post',
          url: '/api/flowclmx.veto.do',
          data: qs.stringify(data)
        }).then(res => {
          //console.log(res)
          Toast(res.data.des)
          if (res.data.flag === '1') {
            if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
              this.loginout()
            }
          }
          this.isDisable = false
          this.$router.push({
            name: 'flowlist',
            query: { idobject: 'flowclmx', actiontype: this.actiontype, actioncode: this.actioncode }
          })
        }).catch(res => {
          this.isDisable = false
          //console.log(res)
          Toast(res)
        })
      }
    },
    submit() {
      if (!this.isDisable) {
        this.isDisable = true
        let data = { id: this.idbill, idflow: this.idflow, idobject: this.idobject }
        this.axios({
          method: 'post',
          url: '/api/flowclmx.submit.do',
          data: qs.stringify(data)
        }).then(res => {
          //console.log(res)
          this.isDisable = false
          Toast(res.data.jsondata)
          this.$router.push({
            name: 'flowlist',
            query: { idobject: 'flowclmx', actiontype: this.actiontype, actioncode: this.actioncode }
          })
        }).catch(res => {
          this.isDisable = false
          //console.log(res)
        })
      }
    },
    back() {
      if (!this.isDisable) {
        this.isDisable = true
        let data = { id: this.idbill, idflow: this.idflow, idobject: this.idobject }
        this.axios({
          method: 'post',
          url: '/api/flowclmx.back.do',
          data: qs.stringify(data)
        }).then(res => {
          //console.log(res)
          Toast(res.data.jsondata.replace('<br>', '\n'))
          this.isDisable = false
          this.$router.push({
            name: 'flowlist',
            query: { idobject: 'flowclmx', actiontype: this.actiontype, actioncode: this.actioncode }
          })
        }).catch(res => {
          this.isDisable = false
          //console.log(res)
        })
      }
    },
    unaudit(object) {
      //console.log('unaudit:', object, this.$route.query.idobject)
      let realObj = this.$route.query.idobject
      let realId = this.$route.query.idbill

      let data = { [realObj + '_id']: realId }

      this.axios({
        method: 'post',
        url: '/api/' + realObj + '.unaudit.do',
        data: qs.stringify(data)
      }).then(res => {
        this.isDisable = false
        if (res.data.flag === '1') {
          Toast(res.data.des)
          if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
            this.loginout()
          }
        } else {
          Toast(res.data.des + ' ')
          this.isDisable = false
          this.$router.push({
            name: 'flowlist',
            query: { idobject: 'flowclmx', actiontype: this.actiontype, actioncode: this.actioncode }
          })
        }
      }).catch(res => {
        this.isDisable = false
        this.reserror(res)
      })
    },
    onLoad(rel) {
      let data = {
        'startline': this.startline,
        'pagecount': this.pagecount,
        'relfield': rel.relfield,
        'relvalue': this.idbill
      }
      let url = ''
      if (rel.current_object === 'flowclmx') {
        url = '/api/' + rel.current_object + '.list-rel.do'
      } else {
        url = '/api/' + rel.current_object + '.list.do'
      }
      this.activeNames = '基本信息'
      this.axios({
        method: 'post',
        url: url,
        data: qs.stringify(data)
      }).then(res => {
        //console.log(res)
        if (res.data.flag === '1') {
          Toast(res.data.des)
          if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
            this.loginout()
          }
        } else {
          let rsdata = res.data.jsondata.fieldValue
          for (let i = 0; i < rsdata.length; i++) {
            this.rellist.push(rsdata[i])
          }
          if (rsdata == null || rsdata.length === 0 || rsdata.length < this.pagecount) {
            this.loading = false
            this.finished = true
          } else {
            this.startline = this.startline + rsdata.length
            this.loading = false
          }
        }
      }).catch(res => {
        this.reserror(res)
      })
    },
    openRel(name, title) {
      this.rellist = []
      this.startline = 1
      //console.log('this.jsondata.relevant: ', this.jsondata.relevant)
      for (let i = 0; i < this.jsondata.relevant.length; i++) {
        let rel = this.jsondata.relevant[i]
        if (name === rel.ui_key) {
          this.currentTabObjectRel=rel
          this.onLoad(rel)
        }
      }
    },
    openRelCard(rel, item) {
      if (rel.current_object === 'flowclmx') {
        Toast('流程信息，不能打开详情！')
        return
      }
      
      let data = { [rel.current_object + '_id']: item.id }
      this.axios({
        method: 'post',
        url: '/api/' + rel.current_object + '.check.do',
        data: qs.stringify(data)
      }).then(res => {

        if (res.data.flag === '1') {
          Toast(res.data.des)
          if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
            this.loginout()
          }
        } else {
          this.reldata = res.data.jsondata
          for (let i = 0; i < this.reldata.Details.length; i++) {
            this.relactiveNames.push(this.reldata.Details[i].groupStitle)
          }
          if (this.actiontype === "mytask" && this.actioncode === "unhandle" && rel.current_object === this.bodyObject) {
            this.relcardshow1 = true
            this.currentTabItemid = item.id
          }else{
            this.relcardshow = true
          }
         
        }
      }).catch(res => {
        this.reserror(res)
      })
    }
  },
  watch: {
    optionshow(val) {
      if (val === false) {
        this.fileList = []
        this.opinion = ''
      }
    }
  },
  // activated () {
  //   if (this.$store.state.ref_show !== '') {
  //     this.turndoneshow = true
  //     this.clr_id = this.$store.state.ref_id
  //     this.clr = this.$store.state.ref_show
  //   }
  //   this.$store.commit('clearRef')
  // }

  activated() {
    //console.log('ref_show', this.$store.state.ref_show)
    //console.log('ref_id', this.$store.state.ref_id)
    if (this.$store.state.ref_show !== '') {
      if (this.turndoneshow) {
        this.clr_id = this.$store.state.ref_id
        this.clr = this.$store.state.ref_show
      } else {
        this.clickmodel.value = this.$store.state.ref_show
        this.clickmodel.valuehidden = this.$store.state.ref_id
        let fieldmap = this.clickmodel.fieldmap
        if (fieldmap !== undefined && fieldmap.length > 0) {
          let arrFieldmap = fieldmap.split(';')
          let item = this.$store.state.ref_item
          if (this.clickfrom === 'headdata') {
            for (let groupindex = 0; groupindex < this.jsondata.head.length; groupindex++) {
              let itemgroup = this.jsondata.head[groupindex]
              for (let itemindex = 0; itemindex < itemgroup.groupvalue.length; itemindex++) {
                let itemdata = itemgroup.groupvalue[itemindex]
                for (let fieldmapindex in arrFieldmap) {
                  let arrFieldMapKey = arrFieldmap[fieldmapindex].split(':')
                  if (this.$store.state.ref_field === arrFieldMapKey[1]) {
                    continue
                  }
                  if (arrFieldMapKey.length === 3 && arrFieldMapKey[2] !== '' && this.$store.state.ref_field !== arrFieldMapKey[2]) {
                    continue
                  }
                  if (itemdata.sField === arrFieldMapKey[1]) {
                    if (itemdata.sUIType === 'ref') {
                      itemdata.value = item[arrFieldMapKey[0] + '_ref']
                      itemdata.valuehidden = item[arrFieldMapKey[0]]
                    } else if (itemdata.sUIType === 'enum') {
                      itemdata.value = item[arrFieldMapKey[0] + '_enum']
                      itemdata.valuehidden = item[arrFieldMapKey[0]]
                    } else {
                      itemdata.value = item[arrFieldMapKey[0]]
                    }
                  }
                }
              }
            }
          } else if (this.clickfrom === 'bodydata') {
            for (let itemindex in this.jsondata.bodydata[this.clickindex]) {
              let itemdata = this.jsondata.bodydata[this.clickindex][itemindex]
              for (let fieldmapindex in arrFieldmap) {
                let arrFieldMapKey = arrFieldmap[fieldmapindex].split(':')
                if (this.$store.state.ref_field === arrFieldMapKey[1]) {
                  continue
                }
                if (arrFieldMapKey.length === 3 && arrFieldMapKey[2] !== '' && this.$store.state.ref_field !== arrFieldMapKey[2]) {
                  continue
                }
                if (itemdata.sField === arrFieldMapKey[1]) {
                  if (itemdata.sUIType === 'ref') {
                    itemdata.value = item[arrFieldMapKey[0] + '_ref']
                    itemdata.valuehidden = item[arrFieldMapKey[0]]
                  } else if (itemdata.sUIType === 'enum') {
                    itemdata.value = item[arrFieldMapKey[0] + '_enum']
                    itemdata.valuehidden = item[arrFieldMapKey[0]]
                  } else {
                    itemdata.value = item[arrFieldMapKey[0]]
                  }
                }
              }
            }
          }
        }
        this.clickmodel = {}
        this.clickindex = 0
        this.clickfrom = ''
      }
      this.$store.commit('clearRef')
    }
  }

}
</script>

<style>
.van-step__circle {
  width: 10px;
  height: 10px;

}


.L-file-lable {
  color: #7e7878;
  font-size: 16px;
  line-height: 24px;
  padding: 10px 16px;
}

.L-popup-container {
  width: 100vw;
  height: 450px;
  border-top: 1px solid #f4f4f4;
  background: #fafafa;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 999;
}

.L-optionBox {
  /* box-sizing: border-box; */
  width: 100%;
  padding: 10px;
  box-sizing: border-box;
}

.L-optionBox .L-optionBox-title {
  width: 95%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px auto;
}

.L-optionBox .messageBox {
  width: 95%;
  border-radius: 10px;
  border: 1px solid #eee;
  padding: 10px;
  margin: 10px auto;
  background: #fff;
}

.L-optionBox .L-upload-btn {
  width: 95vw;
  margin: 10px auto;
}

.L-optionBox .L-fileBox {
  width: 95%;
  margin: 10px auto;
  height: 100px;
  overflow: auto;
}

.L-optionBox .L-fileBox .L-fileBox-item {
  font-size: 14px;
  /* color:#287dd6; */
  color: #606266;
  margin: 5px auto;
}

.fieldgroup_title {
  text-align: left;
  margin: 0px;
  padding: 25px 15px 15px;
  color: rgba(69, 90, 100, 0.6);
  font-weight: normal;
  font-size: 14px;
}

.valueleft {
  min-width: 70%;
  white-space: pre-wrap;
  display: inline-block;
  text-align: left;
  word-break: break-all;
}

.cellvalue1 .van-cell__value {
  position: relative;
  overflow: hidden;
  color: #323233;
  text-align: left;
  vertical-align: middle;
  word-wrap: break-word;
  flex: 2;
}

.cellvalue1 .van-cell__title {
  color: #999;
}
</style>
